package com.rasenhund.android.paintstock.dao;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.rasenhund.android.paintstock.schema.Kanri;

public class KanriDao extends BaseDao {

    public KanriDao(Context context) {
        super(context);
    }

    public KanriDao(Context context, String DbName) {
        super(context, DbName);
    }

    /**
     * 管理マスタの取得
     * 
     * @return
     */
    public Kanri select() {

        Kanri kanri = null;

        // @formatter:off
        String sSql = "";
        sSql += "select master_version";
        sSql += "  from Kanri";
        // @formatter:on

        SQLiteDatabase db = SQLiteDatabase.openDatabase(getDbPath(), null,
                SQLiteDatabase.NO_LOCALIZED_COLLATORS);

        try {
            Cursor cursor = db.rawQuery(sSql, null);
            cursor.moveToFirst();
            if (cursor.getCount() > 0) {

                kanri = new Kanri();

                kanri.setMaster_version(cursor.getInt(0));

            }
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            db.close();
        }

        return kanri;
    }

}
